def searchMatrix(matrix, target):
    """
    :type matrix: List[List[int]]
    :type target: int
    :rtype: bool
    """
    if not matrix:
        return False
    x_left, x_right = 0, len(matrix[0]) - 1
    y_up, y_down = 0, len(matrix) - 1
    while y_down >= y_up:
        x_mid = x_left + (x_right - x_left) // 2
        y_mid = y_up + (y_down - y_up) // 2
        if matrix[y_mid][x_mid] == target:
            return True
        elif matrix[y_mid][x_mid] > target:
            if matrix[y_mid][x_left] == target:
                return True
            elif matrix[y_mid][x_left] > target:
                y_down = y_mid - 1
            else:
                x_right = x_mid - 1
        else:
            if matrix[y_mid][x_right] == target:
                return True
            elif matrix[y_mid][x_right] < target:
                y_up = y_mid + 1
            else:
                x_left = x_mid + 1
    return False


matrix = [[1, 3, 5, 7], [10, 11, 16, 20], [23, 30, 34, 60]]
target = 5
print(searchMatrix(matrix, target))
